using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Network;
using MicroMsg.Plugin.FaceBook;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;
namespace MicroMsg.UI.Page
{
	public class LoginMainView : BasePage
	{
		private const string TAG = "LoginMainView";
		public static string sStrNameToLogin;
		private bool isFromShareContent;
		private string urlExtraInfo = "";
		private EventWatcher m_WatcherLoginErr;
		private EventWatcher m_WatcherLoginSuccess;
		private EventWatcher m_WatcherLoginNeedReg;
		private EventWatcher m_WatcherLoginNeedVCode;
		private EventWatcher m_WatcherLoginByPhone;
		private bool mBIsFirstLoaded = true;
		private EventWatcher faceBookWatcher;
		private ApplicationBar mBar;
		internal Grid LayoutRoot;
		internal panelTitleControl panel1Line;
		internal Pivot pivotLogin;
		internal PivotItem pItemByQQ;
		internal TextBlock textBlockPItemLogin;
		internal Grid LoginTabLayout;
		internal PhoneTextBox textBoxAccount;
		internal WaterMarkPassWordBox textBoxPassword;
		internal Button btnForgetPassword;
		internal Button btnCreateNewAcc1;
		internal StackPanel facebookArea;
		internal Image facebookImg;
		internal Button btnconnectFacebook;
		internal PivotItem pItemLogByPhone;
		internal TextBlock textBlockPItemReg;
		internal InputPhoneNumCtrl mPhoneNumInputer;
		internal SeePrivacyCtrl seePrivacyCtrl;
		internal Button btnForgetPassword2;
		internal Button btnCreateNewAcc2;
		private bool _contentLoaded;
		public LoginMainView()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.LoginMainView_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.LoginMainView_Unloaded));
			if (MMTheme.getThemeType() == MMThemeTypes.COOL_BLACK_THEME)
			{
				this.textBoxAccount.HintStyle = (Style)Application.get_Current().get_Resources().get_Item("cool__HintCustomStyle");
			}
			else
			{
				if (MMTheme.getThemeType() == MMThemeTypes.NORMAL_THEME)
				{
					this.textBoxAccount.HintStyle = (Style)Application.get_Current().get_Resources().get_Item("HintCustomStyle_EX");
				}
			}
			if (TestUserChecker.IsTestVersion())
			{
				this.panel1Line.strTitle = "微信测试版";
			}
			if (FaceBookMgr.LastLoginAsFaceBook())
			{
				return;
			}
			if (FaceBookMgr.IsChina())
			{
				this.facebookArea.set_Visibility(1);
			}
		}
		private void LoginMainView_Unloaded(object sender, RoutedEventArgs e)
		{
			if (this.m_WatcherLoginErr == null)
			{
				return;
			}
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_ERR, this.m_WatcherLoginErr);
			this.m_WatcherLoginErr = null;
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_SUCCESS, this.m_WatcherLoginSuccess);
			this.m_WatcherLoginSuccess = null;
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_NEEDREG, this.m_WatcherLoginNeedReg);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_NEEDVERIFY, this.m_WatcherLoginNeedVCode);
			this.m_WatcherLoginNeedReg = null;
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_SUCCESS, this.m_WatcherLoginByPhone);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_ERR, this.m_WatcherLoginByPhone);
			this.m_WatcherLoginByPhone = null;
			this.FaceBookUnit();
		}
		private void LoginMainView_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.mBIsFirstLoaded)
			{
				this.setAppBar();
				this.mBIsFirstLoaded = false;
				if (!ToolFunction.isEmptyString(GConfigMgr.settings.strLastLoginName))
				{
					try
					{
						this.textBoxAccount.Focus();
						this.textBoxAccount.set_Text(GConfigMgr.settings.strLastLoginName);
						base.Focus();
					}
					catch (Exception)
					{
					}
				}
			}
			if (this.m_WatcherLoginErr == null)
			{
				this.m_WatcherLoginErr = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerLoginErr));
				this.m_WatcherLoginSuccess = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerLoginSuccess));
				this.m_WatcherLoginNeedReg = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerLoginNeedReg));
				this.m_WatcherLoginNeedVCode = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerLoginNeedVCode));
				this.m_WatcherLoginByPhone = new EventWatcher(this, null, new EventHandlerDelegate(this.onPhoneAuthRegHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_ERR, this.m_WatcherLoginErr);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_SUCCESS, this.m_WatcherLoginSuccess);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_NEEDREG, this.m_WatcherLoginNeedReg);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_NEEDVERIFY, this.m_WatcherLoginNeedVCode);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_SUCCESS, this.m_WatcherLoginByPhone);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_ERR, this.m_WatcherLoginByPhone);
			}
			this.FaceBookInit();
		}
		~LoginMainView()
		{
		}
		protected override void OnPageIn(object[] object_0)
		{
		}
		protected override void OnPageOut()
		{
		}
		protected override void OnNavigatedTo(NavigationEventArgs navigationEventArgs_0)
		{
			string text = navigationEventArgs_0.get_Uri().get_OriginalString().ToString();
			int num = text.IndexOf('?');
			if (num <= 0)
			{
				return;
			}
			this.urlExtraInfo = text.Substring(num + 1);
			if (this.urlExtraInfo.Contains("Action=ShareContent"))
			{
				this.isFromShareContent = true;
			}
			base.OnNavigatedTo(navigationEventArgs_0);
		}
		private void btnForgetPassword_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/LoginViews/ForgetPasswordView.xaml", null, false);
		}
		private void btnLogin_Click(object sender, RoutedEventArgs e)
		{
			if (this.textBoxAccount.get_Text() == "")
			{
				MessageBoxManager.ShowToast(strings.Login_Main_MsgNoAcc, 2500, null, false);
				return;
			}
			if (this.textBoxPassword.Password == "")
			{
				MessageBoxManager.ShowToast(strings.Login_Main_MsgNoPass, 2500, null, false);
				return;
			}
			LoginMainView.sStrNameToLogin = this.textBoxAccount.get_Text();
			if (!TestUserChecker.IsTestUser(LoginMainView.sStrNameToLogin))
			{
				MMMessageBox.Show("对不起，你还不是指定的测试用户。", true, "确定");
				return;
			}
			this.disableAllControls();
			ServiceCenter.sceneAuth.doScene(this.textBoxAccount.get_Text(), this.textBoxPassword.Password);
		}
		private void btnRegWithQQ_Click(object sender, RoutedEventArgs e)
		{
			this.pivotLogin.SelectedIndex = 0;
		}
		private void btnRegWithPhoneNum_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/LoginViews/RegByPhoneStepInputNum.xaml", null, false);
		}
		public void DlgReturnEvent(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (dlgReturnEventArg_0 == null)
			{
				return;
			}
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				base.GoToPage("/Source/UI/LoginViews/RegByPhoneStepInputNum.xaml", null, false);
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private void btnRegWithMail_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/LoginViews/RegByMailStepMain.xaml", null, false);
		}
		private void inputTxt_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.get_Key() == 3)
			{
				if (sender == this.textBoxAccount)
				{
					this.textBoxPassword.Focus();
					e.set_Handled(true);
					return;
				}
				if (sender == this.textBoxPassword)
				{
					base.Focus();
					this.btnLogin_Click(null, null);
				}
			}
		}
		private void textBoxAccount_TextChanged(object sender, TextChangedEventArgs e)
		{
			string text = this.textBoxAccount.get_Text();
			if (text == "")
			{
				base.Focus();
				this.textBoxAccount.Focus();
			}
		}
		private void mPhoneNumInputer_mEventDone(object sender, object object_0)
		{
		}
		private void mPhoneNumInputer_mEventNotDone(object sender, object object_0)
		{
		}
		private void btnLoginByPhone_Click(object sender, RoutedEventArgs e)
		{
			bool? isChecked = this.seePrivacyCtrl.cBoxAcceptPcy.get_IsChecked();
			if (!isChecked.GetValueOrDefault() && isChecked.get_HasValue())
			{
				MessageBoxManager.ShowToast(strings.Login_Main_MsgNoReadAgmt, 2500, null, false);
				return;
			}
			if (!this.mPhoneNumInputer.mBIsInputDone)
			{
				MessageBoxManager.ShowToast(strings.Login_GetPassByP_TxtInMobile, 2500, null, false);
				return;
			}
			base.Focus();
			string phoneNumber = this.mPhoneNumInputer.GetPhoneNumber();
			if (!TestUserChecker.IsTestPhoneUser(phoneNumber))
			{
				MMMessageBox.Show("对不起，你还不是指定的测试用户。", true, "确定");
				return;
			}
			this.disableAllControls();
			ServiceCenter.sceneBindOpMobileForReg.doScene(phoneNumber);
			LoginMainView.sStrNameToLogin = phoneNumber;
		}
		private void btnCreateNewAcc_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/LoginViews/RegByPhoneStepInputNum.xaml", null, false);
		}
		private void pushUpPage(int height)
		{
		}
		private void textBoxAccount_GotFocus(object sender, RoutedEventArgs e)
		{
		}
		private void textBoxAccount_LostFoucus(object sender, RoutedEventArgs e)
		{
		}
		private void textBoxPassword_GotFocus(object sender, RoutedEventArgs e)
		{
		}
		private void textBoxPassword_LostFocus(object sender, RoutedEventArgs e)
		{
		}
		private void pivotLoginSelectionChaneged(object sender, RoutedEventArgs e)
		{
			base.Focus();
		}
		private void onEventHandlerLoginErr(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			int num = -(int)evtArgs.mObject;
			if (-6 != num)
			{
				this.processLoginErr(evtArgs);
				InputVCodeControl.DismissInputVcodeBox();
			}
			this.enableAllControls();
		}
		private void onEventHandlerLoginSuccess(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			InputVCodeControl.DismissInputVcodeBox();
			MessageBoxManager.ShowToast(strings.Login_Main_MsgLogSucc, 2500, null, false);
			PageManager.getInstance().PopAllPages(true);
			AuthResponse authResponse = null;
			if (evtArgs.mObject != null && evtArgs.mObject is AuthResponse)
			{
				authResponse = (AuthResponse)evtArgs.mObject;
			}
			GConfigMgr.settings.strLastLoginName = this.textBoxAccount.get_Text();
			GConfigMgr.saveSetting();
			if (this.isFromShareContent)
			{
				base.get_NavigationService().Navigate(new Uri("/Source/UI/ChoosePeopleToShareContent.xaml?" + this.urlExtraInfo, 2));
				return;
			}
			MainPage.GotoThisPage(new object[]
			{
				true,
				authResponse
			}, true);
		}
		private void onEventHandlerLoginNeedReg(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			base.GoToPage("/Source/UI/LoginViews/RegStepSetUserName.xaml", new LoginKind[]
			{
				new LoginKind(LOGINTYPE.REG_TYPE_QQ)
			}, false);
			this.enableAllControls();
		}
		private void onEventHandlerLoginNeedVCode(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.enableAllControls();
			if (evtArgs != null)
			{
				if (InputVCodeControl.IsShown())
				{
					InputVCodeControl.SetInputVCodeBoxWrongStage(evtArgs);
					return;
				}
				InputVCodeControl.Show(true, evtArgs, this.textBoxAccount.get_Text(), this.textBoxPassword.Password, null, null);
			}
		}
		private void onPhoneAuthRegHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			this.enableAllControls();
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_SUCCESS)
			{
				RegByPhoneStepInputNum.sStrNameToLogin = LoginMainView.sStrNameToLogin;
				base.GoToPage("/Source/UI/LoginViews/RegByPhoneStepInputVCode.xaml", new object[]
				{
					LoginMainView.sStrNameToLogin
				}, false);
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_ERR)
			{
				if (evtArgs.mObject == null)
				{
					Log.smethod_5("LoginMainView", "onPhoneAuthRegHandler:evtArgs.mObject is null");
					return;
				}
				RetConst retConst = (RetConst)evtArgs.mObject;
				Log.smethod_5("LoginMainView", "onPhoneAuthRegHandler:evtArgs.mObject is" + retConst);
				RetConst retConst2 = retConst;
				if (retConst2 > RetConst.MM_ERR_MOBILE_NEEDADJUST)
				{
					switch (retConst2)
					{
					case RetConst.MM_ERR_USER_BIND_MOBILE:
						break;
					case RetConst.MM_ERR_USER_MOBILE_UNMATCH:
						goto IL_FD;
					case RetConst.MM_ERR_MOBILE_FORMAT:
						MMMessageBox.Show(strings.PCon_Bind_Msg_BindPhone_FormatTip, true, "确定");
						return;
					default:
						switch (retConst2)
						{
						case RetConst.MM_ERR_MOBILE_BINDED:
							break;
						case RetConst.MM_ERR_FREQ_LIMITED:
							MMMessageBox.Show(strings.Reg_PhoneNum_MsgTooFreq, true, "确定");
							return;
						default:
							goto IL_FD;
						}
						break;
					}
					base.GoToPage("/Source/UI/LoginViews/LogByPhonePassword.xaml", null, false);
					return;
				}
				if (retConst2 == RetConst.MM_ERR_CLIENT)
				{
					MMMessageBox.Show(strings.Reg_PhoneNum_MsgBadNet, true, "确定");
					return;
				}
				if (retConst2 == RetConst.MM_ERR_MOBILE_NEEDADJUST)
				{
					MMMessageBox.Show(strings.PCon_Bind_Msg_BindPhone_NeedAdjust, true, "确定");
					return;
				}
				IL_FD:
				MMMessageBox.Show(strings.Reg_PhoneNum_MsgBadNum, true, "确定");
			}
		}
		private void processLoginErr(BaseEventArgs evtArgs)
		{
			if (ServerBulletin.isFaultMode())
			{
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Bulletin_OOB_Title, strings.Bulletin_OOB_Desc, true, strings.Bulletin_Ignore, strings.Bulletin_ViewOOB);
				mMMessageBox.set_FontSize(22.0);
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.MsgBoxClearDataHandler);
				return;
			}
			RetConst retConst = (RetConst)evtArgs.mObject;
			RetConst retConst2 = retConst;
			if (retConst2 == RetConst.MM_ERR_CLIENT)
			{
				MMMessageBox.Show(strings.Login_Main_MsgBadNet, true, "确定");
				return;
			}
			if (retConst2 != RetConst.MM_ERR_USEREXIST)
			{
				MMMessageBox.Show(strings.Login_Main_MsgBadAcc, true, "确定");
				return;
			}
			MMMessageBox.Show("该facebook已经被绑定到其它帐号，请使用对应微信帐号登录", true, "确定");
		}
		public void MsgBoxClearDataHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				break;
			case 1:
				base.GoToPage("/Source/UI/Bulletin/ServerBulletinPage.xaml", new object[]
				{
					ServerBulletin.getBulletinUrl(AccountMgr.strUsrName, R.GetCurrentLanguage())
				}, false);
				break;
			default:
				return;
			}
		}
		private void enableAllControls()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		private void disableAllControls()
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.Login_Main_MsgSending, null, false, false, null);
		}
		private void btnconnectFacebook_Click(object sender, RoutedEventArgs e)
		{
			FaceBookLoginPage.ShowFaceBookLoginPage(this, new FaceBookLoginCallBack(this.FaceBookLoginCB), true);
		}
		public void FaceBookLoginCB(bool isSuccess, string strToken)
		{
			if (!isSuccess)
			{
				return;
			}
			if (string.IsNullOrEmpty(strToken))
			{
				return;
			}
			this.disableAllControls();
			MainPage.IsRegisterFromFacebook = true;
			ServiceCenter.sceneAuth.doScene("facebook@wechat_auth", strToken);
			FaceBookMgr.SetLastLoginAsFaceBook(true);
		}
		private void FaceBookInit()
		{
			this.faceBookWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onBindEvent));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_FACEBOOK_EVENT, this.faceBookWatcher);
		}
		private void FaceBookUnit()
		{
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_FACEBOOK_EVENT, this.faceBookWatcher);
		}
		private void onBindEvent(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private ApplicationBar setAppBar()
		{
			if (this.mBar != null)
			{
				if (!this.mBar.get_IsVisible())
				{
					this.mBar.set_IsVisible(true);
				}
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/Resource/Img/CommonUse/ico_nextStep.png", 2));
			applicationBarIconButton.set_Text(strings.COM_Next);
			applicationBarIconButton.add_Click(new EventHandler(this.btnNext_Click));
			this.mBar.get_Buttons().Add(applicationBarIconButton);
			base.set_ApplicationBar(this.mBar);
			this.setAppBarStyle(base.get_ApplicationBar());
			return this.mBar;
		}
		private void btnNext_Click(object sender, EventArgs e)
		{
			base.Focus();
			if (this.pivotLogin.SelectedIndex == 0)
			{
				this.btnLogin_Click(null, null);
				return;
			}
			this.btnLoginByPhone_Click(null, null);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/LoginViews/LoginMainView.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panel1Line = (panelTitleControl)base.FindName("panel1Line");
			this.pivotLogin = (Pivot)base.FindName("pivotLogin");
			this.pItemByQQ = (PivotItem)base.FindName("pItemByQQ");
			this.textBlockPItemLogin = (TextBlock)base.FindName("textBlockPItemLogin");
			this.LoginTabLayout = (Grid)base.FindName("LoginTabLayout");
			this.textBoxAccount = (PhoneTextBox)base.FindName("textBoxAccount");
			this.textBoxPassword = (WaterMarkPassWordBox)base.FindName("textBoxPassword");
			this.btnForgetPassword = (Button)base.FindName("btnForgetPassword");
			this.btnCreateNewAcc1 = (Button)base.FindName("btnCreateNewAcc1");
			this.facebookArea = (StackPanel)base.FindName("facebookArea");
			this.facebookImg = (Image)base.FindName("facebookImg");
			this.btnconnectFacebook = (Button)base.FindName("btnconnectFacebook");
			this.pItemLogByPhone = (PivotItem)base.FindName("pItemLogByPhone");
			this.textBlockPItemReg = (TextBlock)base.FindName("textBlockPItemReg");
			this.mPhoneNumInputer = (InputPhoneNumCtrl)base.FindName("mPhoneNumInputer");
			this.seePrivacyCtrl = (SeePrivacyCtrl)base.FindName("seePrivacyCtrl");
			this.btnForgetPassword2 = (Button)base.FindName("btnForgetPassword2");
			this.btnCreateNewAcc2 = (Button)base.FindName("btnCreateNewAcc2");
		}
	}
}
